﻿#define HAS_VIEWED_ANNOTATIONS

using System;
using Microsoft.Practices.Unity;

using SharedGenomics.Core.Configuration;
using SharedGenomics.Workbench.Presenters;


namespace SharedGenomics.Workbench.Core.Configuration
{
    /// <summary>
    /// Regsiters various 'application' services with the container. Note that this strategy should come after the <see cref="CoreContainerConfigurationStrategy"/>,
    /// ,<see cref="FrameworkContainerConfigurationStrategy"/> and a strategy for registering the views
    /// </summary>
    public class ApplicationContainerConfigurationStrategy : IContainerConfigurationStrategy
    {
        public void Configure(ContainerConfigurationContext context)
        {
            var container = context.Container;

            container.RegisterType<IApplicationController, ApplicationController>(new ContainerControlledLifetimeManager());

            //register tasks and their associated presenters
            TaskRegistry tr = new TaskRegistry();
            var presenterFactory = container.Resolve<PresenterFactory>();

            //comment out the line below and uncomment the one below that to change the layout of the initial 'file set upload' form
            //tr.AddTask(new Task<FileSetUploadPresenter>("FileSetUpload", "Upload File Set", presenterFactory));
            tr.AddTask(new DataFileUploadTask(presenterFactory));

            tr.AddTask(new Task<DataFilterPresenter>("DataFilter", "Create Data Set", presenterFactory));
            tr.AddTask(new Task<JobSubmissionPresenter>("JobSubmission", "Submit Job", presenterFactory));
            tr.AddTask(new Task<AnalysisResultsPresenter>("AnalysisResults", "Analysis Results", presenterFactory));
#if HAS_VIEWED_ANNOTATIONS
            tr.AddTask(new Task<AnnotationResultsPresenter>("AnnotationResults", "Show annotations...", presenterFactory));
#endif

            container.RegisterInstance<ITaskRegistry>(tr, new ContainerControlledLifetimeManager());

#if HAS_VIEWED_ANNOTATIONS
            container.RegisterType<IUriNavigator, InternalUriNavigator>(new ContainerControlledLifetimeManager());
#else
            container.RegisterType<IUriNavigator, ExternalUriNavigator>(new ContainerControlledLifetimeManager());
#endif

            //NOTE: bit of a hack but we need to make sure the UriNavigator has been created so it will be registered with the event broker...
            container.Resolve<IUriNavigator>();

            container.RegisterType<CommandFactory>();
        }
    }
}
